import React, { memo } from "react";
import { connect } from "react-redux";
import { changeCountAction } from "./store/modules/count";

const App = memo((props) => {
  const { count, changeCount } = props

  function changeCountHandle(val) {
    changeCount(val)
  }
  return (
    <div>
      当前计数：{ count }
      <button onClick={e => changeCountHandle(1)}>+1</button>
      <button onClick={e => changeCountHandle(-1)}>-1</button>
    </div>
  )
});

const mapStateToProps = (state) => ({
  count: state.count.count
})

const mapDispatchToProps = (dispatch) => ({
  changeCount(val) {
    dispatch(changeCountAction(val))
  }
})
export default connect(mapStateToProps, mapDispatchToProps)(App);
